package part
{
	import effects.fractal.JuliaEffect;
	import effects.post.DowngradeEffect;
	import effects.chroma.ChromaBlurEffect;
	import effects.post.BloomEffect;
	import evo.engine.IDemoPart;
	import evo.engine.DemoEngine;
	import evo.engine.AbstractPart;

	public class TestPart extends AbstractPart
	{
		private var juliaEffect:JuliaEffect;
		private var juliaDg:DowngradeEffect;
		
		private var chromaBlur:ChromaBlurEffect;
		private var bloom:BloomEffect;
	
		private var offset:Number = 0;
		private var sync:DemoSynch;
		
		public function TestPart(sync:DemoSynch)
		{
			this.sync = sync;
			super(sync);
		}
		
		override public function prePlay(dt:Number):void
		{
			offset = (offset - offset / 5);
//			chromaBlur.offsetScale = offset;
		}
		
		override public function postPlay(dt:Number):void
		{
		}
		
		override public function preInit(engine:DemoEngine):void
		{
			super.preInit(engine);

			juliaDg = new DowngradeEffect();
			juliaDg.init({scale:2});

			chromaBlur = new ChromaBlurEffect();
			chromaBlur.init({offset:10});

			bloom = new BloomEffect();
			bloom.init({});

			juliaEffect = new JuliaEffect();
			juliaEffect.init({});
		}
		
		override public function init(engine:DemoEngine):void
		{
			super.init(engine);
			engine.addEffect(juliaDg);
			juliaDg.addEffect(chromaBlur);
			chromaBlur.addEffect(bloom);
			bloom.addEffect(juliaEffect);

			sync.bassDrum.addListener(on_bd);
		}

		override protected function cleanup():void
		{
			sync.bassDrum.removeListener(on_bd);
			engine.removeEffect(juliaEffect);
		}

		protected function on_bd(t:uint):void
		{
			offset = 32;
		}
	}
}